<template>
	<view class="plr15">
		<view class="list-content mt15 plr15" v-for="(item,index) in list">
			<view class="flex spaceb alcenter plt10">
				<view class="fl1 ">
					<view class="ftw600 ft18">编号：{{item.number}}</view>
				</view>
				<view class="ft18 btn" v-if="item.status==0" style="color: #FF8400;">未使用</view>
				<view class="ft18 btn" v-if="item.status==1" style="color: #01C255;">已使用</view>
			</view>
			<view class="flex alcenter plt10 border-bottom" v-if="item.goods" style="border-top: 1px solid #e5e5e5;">
				<image :src="item.goods.thumb" mode="" style="width: 120rpx;height: 120rpx;"></image>
				<view class="ml10">
					<view>{{item.goods.name}}</view>
					<view class="mt10" style="color: #44cc00;">￥{{item.goods.jiage}}</view>
				</view>
			</view>
			<view class="flex end plt10">
				<view class="edit ml10" @click="openFun2(item.id)">打开该柜门</view>
				<view class="edit ml10" @click="openFun(item.id)">编辑有货/无货</view>
				<view class="edit ml10" @click="editFun(item.id)">编辑</view>
			</view>
		</view>
		<u-popup mode="bottom" v-model="show" height="600px">
			<view class="">
				<scroll-view scroll-y="true" style="height: 520px;">
					<view>
						<view class="pd15 border-bottom flex spaceb alcenter" v-for="(item,index) in goodList"
							:key="index" :class="{'act':intindex===index}" @click="orderchange(index,item.id)">
							<view class="flex alcenter">
								<image :src="item.thumb" mode="" style="width: 120rpx;height: 120rpx;"></image>
								<view class="ml10">
									<view>{{item.name}}</view>
									<view class="mt10" style="color: #44cc00;">￥{{item.jiage}}</view>
								</view>
							</view>
							<image src="@/static/images/select.png" mode="" v-if="intindex===index"
								style="width: 40rpx;height: 40rpx;"></image>
						</view>
					</view>
				</scroll-view>
				<view class="confrim-btn pd15">
					<u-button @click="confirm">确定</u-button>
				</view>
			</view>
		</u-popup>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				show: false,
				list: [],
				cabinetid: "",
				goodList: [],
				intindex: 0,
				id: 0,
				gid: 0
			}
		},
		onLoad(o) {
			this.cabinetid = o.cabinetid
			this.getshopList()
		},
		onShow() {
			this.getGzlist()
			//#ifdef MP-WEIXIN
			wx.showShareMenu({
				withShareTicket: true,
				menus: ['shareAppMessage', 'shareTimeline']
			})

			//#endif
		},
		methods: {
			editFun(id) {
				this.show = true
				this.id = id

			},
			confirm() {
				this.global.request.post({
					data: {
						do: 'cabinetdetail',
						id: this.id,
						gid: this.gid
					},
					success: res => {
						
							uni.showToast({
								title: '编辑成功',
								icon: 'none'
							})
							
						this.getGzlist()
						this.show = false
					}
				})
			},
			openFun(id){
				this.global.request.post({
					data: {
						do: 'Setstatus',
						id: id
					},
					success: res => {
						this.getGzlist()
						 
					}
				})
			},
			openFun2(id){
				this.global.request.post({
					data: {
						do: 'Setstatus2',
						id: id,
					},
					success: res => {
						uni.showToast({
							title: ''+res,
							icon: 'none'
						})
					}
				})
			},
			orderchange(e, id) {
				this.intindex = e
				this.gid = id
			},
			makecall(index) {
				uni.makePhoneCall({
					phoneNumber: this.allstore[index].phone
				})
			},
			getGzlist() {
				this.global.request.post({
					data: {
						do: 'Cabinet_detail',
						cabinetid: this.cabinetid
					},
					success: res => {
						this.list = res
					}
				})
			},
			getshopList() {
				var that = this;
				this.global.request.post({
					data: {
						do: 'Goods_list',
						id: uni.getStorageSync('s_id'),
					},
					success: res => {
						this.goodList = res.list
					}
				})
				// api.ApiGet({
				// 	op: '',
				// 	do: 'Goods_list',
				// 	s_id: uni.getStorageSync('s_id'),
				// 	id: that.id,
				// 	sort: that.filterIndex,
				// 	paixu: paixu,
				// 	page: that.page,
				// 	lowInput: that.lowInput,
				// 	tallInput: that.tallInput,
				// 	keywords: that.InfoInput
				// }, function(res) {
				// 	var datatime = res.data.datas.list

				// 	for (var i = 0; i < datatime.length; i++) {
				// 		var obj = {}
				// 		obj.shopid = datatime[i].id
				// 		obj.time = datatime[i].auto_xiajia_time
				// 		that.goodsList.push(obj)
				// 	}
				// 	that.zhuangtai = 0
				// 	if (that.page == 0) {
				// 		that.list = res.data.datas.list
				// 	} else {
				// 		that.list = that.list.concat(res.data.datas.list);
				// 	}

				// 	that.recordtab = res.data.datas.class;
				// 	that.menu = res.data.datas.menu;

				// 	if (res.data.datas.list.length > 0) {

				// 		that.page = that.page + 1
				// 	} else {
				// 		that.zhuangtai = 2
				// 	}
				// 	// that.timeFun();
				// })
			}
		}
	}
</script>
<style>
	page {
		background: #F7F7F7;
	}
</style>
<style lang="scss" scoped>
	.content {
		padding: 24rpx;
		text-align: center;
	}

	.list-content {
		border-radius: 20rpx;
		background: #FFFFFF;
	}

	button {
		width: 92%;
		background-color: #FD7A4D;
		color: white;
		position: fixed;
		bottom: 0;
		margin-bottom: 20rpx;
	}

	.border-bottom {
		border-bottom: 1px solid #e5e5e5;
	}

	.btn {
		// width: 140rpx;
		border-radius: 0 20rpx 20rpx 0;
		color: #FFFFFF;
		text-align: center;
		font-weight: bold;
	}

	.edit {
		// width: 140rpx;
		border-radius: 20rpx;
		padding: 10rpx 30rpx;
		text-align: center;
		font-weight: bold;
		background-color: #44cc00;
		color: #FFFFFF;
	}

	.act {
		background-color: #FEF2EA;
	}
</style>
